package cn.wolfcode.shopclientmgrsite.controller;



import cn.wolfcode.order.domain.OrderInfo;
import cn.wolfcode.order.query.OrderInfoQueryObject;
import cn.wolfcode.order.query.QueryObject;
import cn.wolfcode.order.service.IOrderActionService;
import cn.wolfcode.order.service.IOrderInfoService;
import cn.wolfcode.order.service.IOrderProductService;
import cn.wolfcode.order.util.JSONResult;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;


@Controller
public class OrderInfoController {

    @Reference
    private IOrderInfoService orderInfoService;
    @Reference
    private IOrderProductService orderProductService;
    @Reference
    private IOrderActionService actionService;

    /**
     * 进入商品列表页面
     * @return
     */
    @RequestMapping("/order_list")
    public String  list(Model model, @ModelAttribute("qo")OrderInfoQueryObject qo){
       model.addAttribute("pageInfo",orderInfoService.query(qo));
        return "orderInfo/orderInfo";
    }

   //----------订单确认--------------
    @RequestMapping("/orderInfo_verify")
    public String  orderInfoVerify(Model model, @ModelAttribute("qo")OrderInfoQueryObject qo){
       model.addAttribute("pageInfo",orderInfoService.selectOrderNoVerify(qo));
        return "orderInfo/orderInfo_verify";
    }

    @RequestMapping("/changeOrderStatus")
    public String changeOrderStatus(Long id){
        orderInfoService.changeOrderStatus(id);
        return "redirect:orderInfo_verify";
    }

   //----------确认发货--------------
    @RequestMapping("/orderInfo_deliver")
    public String  shippingStatus(Model model, @ModelAttribute("qo")OrderInfoQueryObject qo){
       model.addAttribute("pageInfo",orderInfoService.selectOrderNoDeliver(qo));
        return "orderInfo/orderInfo_deliver";
    }
    @RequestMapping("/changeShippingStatus")
    public String changeShippingStatus(Long id){
        System.out.println("雷猴啊,id="+id);
        orderInfoService.changeShippingStatus(id);
        return "redirect:orderInfo_deliver";
    }

    //--------订单详情--------------
    @RequestMapping("selectOrder")
    public String get(Model model,Integer id){
        model.addAttribute("order",orderInfoService.getOne(id));
        model.addAttribute("goodsList",orderProductService.getGoods(Long.valueOf(id)));
        model.addAttribute("orderActionList",actionService.getAction(Long.valueOf(id)));
        return "orderInfo/editOrderUI";
    }

}
